/*
 *   AS IS License
 * ==Naive Coders==
 */
package org.naive.metawatch.converter.cap;

import java.text.ParseException;
import org.naive.metawatch.converter.parser.cap.CapParseContext;
import org.naive.metawatch.converter.parser.cap.CapParseable;

/**
 *
 * @author gbu.000
 */
public abstract class CapComponent extends CapParseable {

    protected byte tag;
    protected short size;

    protected void parseHeader(CapParseContext px) throws ParseException {
        tag = px.readByte();
        size = px.readShort();
        px.startBlock(size);
    }

    protected void endParsing(CapParseContext px) {
        px.endBlock();
    }

    protected void parseAutomaticFields(CapParseContext px) throws ParseException {
        super.parse(px);
    }

    @Override
    public void parse(CapParseContext px) throws ParseException {
        parseHeader(px);
        parseAutomaticFields(px);
        endParsing(px);
    }
}
